/*
 * Copyright (C) 2017 volders GmbH with <3 in Berlin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package berlin.volders.badger.example.slice;

import berlin.volders.badger.BadgeShape;
import berlin.volders.badger.FloatRange;
import berlin.volders.badger.example.ResourceTable;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Rect;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;

class CustomBadgeShape extends BadgeShape {

    public static final float NUM_D1F = 0.1f;

    private final RectFloat region;
    private final Paint paint;

    CustomBadgeShape(Context context, @FloatRange(from = 0, to = 1) float scale, int gravity) {
        super(scale, 1, gravity);
        region = new RectFloat();
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(new Color(getBorderColor(context)));
    }

    private static int getBorderColor(Context context) {
        return ResourceTable.Color_transparent;
    }

    /**
     * 绘制
     *
     * @see BadgeShape#circle(float, int)
     * @param canvas to draw on
     * @param region to draw in
     * @param paint  to draw with
     */
    @Override
    protected void onDraw(Canvas canvas, Rect region, Paint paint) {
        float extX = region.getWidth() * NUM_D1F;
        float extY = region.getHeight() * NUM_D1F;
        this.region.left = region.left;
        this.region.top = region.top;
        this.region.right = region.right;
        this.region.bottom = region.bottom;
        this.region.left -= extX;
        this.region.top -= extY;
        this.region.right += extX;
        this.region.bottom += extY;
        canvas.drawOval(this.region, this.paint);
        this.region.left = region.left;
        this.region.top = region.top;
        this.region.right = region.right;
        this.region.bottom = region.bottom;
        canvas.drawOval(this.region, paint);
    }
}